<%--
  Created by IntelliJ IDEA.
  User: 世界上最帅的詹姆斯
  Date: 2021-01-15
  Time: 11:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath=request.getScheme()+"://"
            +request.getServerName()+":"+request.getServerPort()
            +request.getContextPath()+"/";
%>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link href="../../layui/css/layui.css" media="all" rel="stylesheet">
<body>
<center>
    <form class=" layui-form layui-form-pane" method="post" >
        <div class="layui-form-item" >
            <div class="layui-inline" style="top: 100px;width: 250px" >
                <label class="layui-form-label" >ID</label>
                <div class="layui-input-inline" >
                    <input type="text" name="id"  autocomplete="off" class="layui-input" placeholder="ID为整型">
                </div>
            </div>
        </div>
        <dic class="layui-form-item">
            <div class="layui-inline" style="top: 150px;width: 250px">
                <label class="layui-form-label" >消费类型</label>
                <div class="layui-input-inline" >
                    <input type="text" name="cname"  autocomplete="off" class="layui-input" placeholder="请输入消费类型">
                </div>
            </div>
        </dic>
        <div class="layui-form-item">
            <div class="layui-input-block" style="top: 180px;left: -50px">
                <button type="submit" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary layui-btn-radius">重置</button>
            </div>
        </div>
    </form>
</center>
<script src="../../layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form','jquery'],function () {
        var  form=layui.form;
        var $=layui.jquery;
        //监听提交
        form.on('submit(demo1)',function(data) {
            var index = layer.msg('提交中，请稍候',{icon: 16,time:false,shade:0.8});
            $.ajax({
                url: '<%=basePath%>basic/addConsumption',
                dataType: 'json',
                type: 'post',
                data:data.field,
                async: false,
                success : function(data) {
                    if (data === false) {
                        layer.msg('录入失败！', {
                            icon : 5,
                            offset : "auto",
                            time : 2000
                        });//提示框
                    } else if (data===true){
                        layer.alert('添加成功',{incon:6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //修改成功后刷新父界面
                            window.parent.location.reload();
                        })
                    }
                }
            })
            return false;
        })
    })


</script>
</body>
</html>
